import React, {Component} from 'react';
import { Badge,Card,NoticeBar, Button,Scroller,Popup,Group, Field, Toast,NumberPicker, CheckboxField,SelectField, SwitchField  } from 'saltui';
import $ from 'jquery'
// <InputSwitch defaultValue option onChange>
export default class InputChecked extends React.Component {

  constructor(props) {
    super(props);


    let option = this.props.option;
    let defaultValue = this.props.defaultValue;

    if (defaultValue) {
      option.map(function (value, key) {
        if (defaultValue.indexOf(value.value) !=-1) {
          option[key].checked = true;
        }
      })
    }

   let newoption = $.extend(true,[],option);

    this.state = {
      value: this.props.value,
      option:newoption
    };



  }

  render() {
    let that = this;
    let option = {
      data: this.state.option,
      placeholder: '请选择',
      onChange(data) {
        let arr = [];
        data.map(function (value, index) {
          arr[index] = value.value;
        })
        if(arr.length <1){
          arr = "";
        }
        that.props.onChange(that.props.id, arr);
      },
      mode: 'list',
    };
    return <CheckboxField
      {...option}
      mode="slot"
    />

  }

}
